<?php
if($this->do=='module'){
	$this->check_access('global_module');
	$array=array();
	if($handle=opendir("core/modules/")){
		while(false!==($dir=readdir($handle))){
			if ($dir!="."&&$dir!=".."&&is_dir(ROOT.'/core/modules/'.$dir)){
				$info=@include(ROOT.'/core/modules/'.$dir.'/info.php');
				if(!empty($info)){
					$info['install']=file_exists(ROOT.'/core/modules/'.$dir.'/install.lock.php');
					$info['dir']=$dir;
					$array[]=$info;
				}
			}
		}
		closedir($handle);
	}

	$this->template->in("module_list",$array);
	$this->template->out('global.module.php');
}
if($this->do=='module_install'){
	$this->check_access('global_module');
	$dir=empty($_GET['dir'])?'':trim($_GET['dir']);
	$install_path=ROOT.'/core/modules/'.$dir.'/install.php';
	$uninstall_path=ROOT.'/core/modules/'.$dir.'/uninstall.lock.php';
	include($install_path);
	@rename($install_path,str_replace('install','install.lock',$install_path));
	@rename($uninstall_path,str_replace('uninstall.lock','uninstall',$uninstall_path));
	clear_cache();
}
if($this->do=='module_uninstall'){
	$this->check_access('global_module');
	$dir=empty($_GET['dir'])?'':trim($_GET['dir']);
	$install_path=ROOT.'/core/modules/'.$dir.'/install.lock.php';
	$uninstall_path=ROOT.'/core/modules/'.$dir.'/uninstall.php';
	include($uninstall_path);
	@rename($install_path,str_replace('install.lock','install',$install_path));
	@rename($uninstall_path,str_replace('uninstall','uninstall.lock',$uninstall_path));
	clear_cache();
}